import type { IObject } from '@/lib/api/types';

const expressionJson = [
  { meaning: '[微笑]', url: 'appkefu_f001.png' },
  { meaning: '[撇嘴]', url: 'appkefu_f002.png' },
  { meaning: '[色]', url: 'appkefu_f003.png' },
  { meaning: '[发呆]', url: 'appkefu_f004.png' },
  { meaning: '[得意]', url: 'appkefu_f005.png' },
  { meaning: '[流泪]', url: 'appkefu_f006.png' },
  { meaning: '[害羞]', url: 'appkefu_f007.png' },
  { meaning: '[闭嘴]', url: 'appkefu_f008.png' },
  { meaning: '[睡]', url: 'appkefu_f009.png' },
  { meaning: '[大哭]', url: 'appkefu_f010.png' },

  { meaning: '[尴尬]', url: 'appkefu_f011.png' },
  { meaning: '[发怒]', url: 'appkefu_f012.png' },
  { meaning: '[调皮]', url: 'appkefu_f013.png' },
  { meaning: '[呲牙]', url: 'appkefu_f014.png' },
  { meaning: '[惊讶]', url: 'appkefu_f015.png' },
  { meaning: '[难过]', url: 'appkefu_f016.png' },
  { meaning: '[酷]', url: 'appkefu_f017.png' },
  { meaning: '[囧]', url: 'appkefu_f018.png' },
  { meaning: '[抓狂]', url: 'appkefu_f019.png' },
  { meaning: '[吐]', url: 'appkefu_f020.png' },

  { meaning: '[偷笑]', url: 'appkefu_f021.png' },
  { meaning: '[愉快]', url: 'appkefu_f022.png' },
  { meaning: '[白眼]', url: 'appkefu_f023.png' },
  { meaning: '[傲慢]', url: 'appkefu_f024.png' },
  { meaning: '[饥饿]', url: 'appkefu_f025.png' },
  { meaning: '[困]', url: 'appkefu_f026.png' },
  { meaning: '[惊恐]', url: 'appkefu_f027.png' },
  { meaning: '[流汗]', url: 'appkefu_f028.png' },
  { meaning: '[憨笑]', url: 'appkefu_f029.png' },
  { meaning: '[悠闲]', url: 'appkefu_f030.png' },
  { meaning: '[奋斗]', url: 'appkefu_f031.png' },
  { meaning: '[咒骂]', url: 'appkefu_f032.png' },
  { meaning: '[疑问]', url: 'appkefu_f033.png' },
  { meaning: '[嘘]', url: 'appkefu_f034.png' },
  { meaning: '[晕]', url: 'appkefu_f035.png' },
  { meaning: '[疯了]', url: 'appkefu_f036.png' },
  { meaning: '[衰]', url: 'appkefu_f037.png' },
  { meaning: '[骷髅]', url: 'appkefu_f038.png' },
  { meaning: '[敲打]', url: 'appkefu_f039.png' },
  { meaning: '[再见]', url: 'appkefu_f040.png' },

  { meaning: '[擦汗]', url: 'appkefu_f041.png' },
  { meaning: '[抠鼻]', url: 'appkefu_f042.png' },
  { meaning: '[鼓掌]', url: 'appkefu_f043.png' },
  { meaning: '[糗大了]', url: 'appkefu_f044.png' },
  { meaning: '[坏笑]', url: 'appkefu_f045.png' },
  { meaning: '[左哼哼]', url: 'appkefu_f046.png' },
  { meaning: '[右哼哼]', url: 'appkefu_f047.png' },
  { meaning: '[哈欠]', url: 'appkefu_f048.png' },
  { meaning: '[鄙视]', url: 'appkefu_f049.png' },
  { meaning: '[委屈]', url: 'appkefu_f050.png' },

  { meaning: '[快哭了]', url: 'appkefu_f051.png' },
  { meaning: '[阴险]', url: 'appkefu_f052.png' },
  { meaning: '[亲亲]', url: 'appkefu_f053.png' },
  { meaning: '[吓]', url: 'appkefu_f054.png' },
  { meaning: '[可怜]', url: 'appkefu_f055.png' },
  { meaning: '[菜刀]', url: 'appkefu_f056.png' },
  { meaning: '[西瓜]', url: 'appkefu_f057.png' },
  { meaning: '[啤酒]', url: 'appkefu_f058.png' },
  { meaning: '[篮球]', url: 'appkefu_f059.png' },
  { meaning: '[乒乓]', url: 'appkefu_f060.png' },

  { meaning: '[咖啡]', url: 'appkefu_f061.png' },
  { meaning: '[饭]', url: 'appkefu_f062.png' },
  { meaning: '[蛋糕]', url: 'appkefu_f069.png' },
  { meaning: '[玫瑰]', url: 'appkefu_f064.png' },
  { meaning: '[凋谢]', url: 'appkefu_f065.png' },
  { meaning: '[嘴唇]', url: 'appkefu_f066.png' },
  { meaning: '[爱心]', url: 'appkefu_f067.png' },
  { meaning: '[心碎]', url: 'appkefu_f068.png' },

  { meaning: '[猪头]', url: 'appkefu_f063.png' },
  { meaning: '[闪电]', url: 'appkefu_f070.png' },

  { meaning: '[炸弹]', url: 'appkefu_f071.png' },
  { meaning: '[刀]', url: 'appkefu_f072.png' },
  { meaning: '[足球]', url: 'appkefu_f073.png' },
  { meaning: '[瓢虫]', url: 'appkefu_f074.png' },
  { meaning: '[便便]', url: 'appkefu_f075.png' },
  { meaning: '[月亮]', url: 'appkefu_f076.png' },
  { meaning: '[太阳]', url: 'appkefu_f077.png' },
  { meaning: '[礼物]', url: 'appkefu_f078.png' },
  { meaning: '[拥抱]', url: 'appkefu_f079.png' },
  { meaning: '[强]', url: 'appkefu_f080.png' },

  { meaning: '[弱]', url: 'appkefu_f081.png' },
  { meaning: '[握手]', url: 'appkefu_f082.png' },
  { meaning: '[胜利]', url: 'appkefu_f083.png' },
  { meaning: '[抱拳]', url: 'appkefu_f084.png' },
  { meaning: '[勾引]', url: 'appkefu_f085.png' },
  { meaning: '[拳头]', url: 'appkefu_f086.png' },
  { meaning: '[差劲]', url: 'appkefu_f087.png' },
  { meaning: '[爱你]', url: 'appkefu_f088.png' },
  { meaning: '[No]', url: 'appkefu_f089.png' },
  { meaning: '[OK]', url: 'appkefu_f090.png' },

  { meaning: '[爱情]', url: 'appkefu_f091.png' },
  { meaning: '[飞吻]', url: 'appkefu_f092.png' },
  { meaning: '[跳跳]', url: 'appkefu_f093.png' },
  { meaning: '[发抖]', url: 'appkefu_f094.png' },
  { meaning: '[怄火]', url: 'appkefu_f095.png' },
  { meaning: '[转圈]', url: 'appkefu_f096.png' },
  { meaning: '[磕头]', url: 'appkefu_f097.png' },
  { meaning: '[回头]', url: 'appkefu_f098.png' },
  { meaning: '[跳绳]', url: 'appkefu_f099.png' },

  { meaning: '[投降]', url: 'appkefu_f100.png' },
  { meaning: '[激动]', url: 'appkefu_f101.png' },
  { meaning: '[乱舞]', url: 'appkefu_f102.png' },
  { meaning: '[献吻]', url: 'appkefu_f103.png' },
  { meaning: '[左太极]', url: 'appkefu_f104.png' },
  { meaning: '[右太极]', url: 'appkefu_f105.png' }
];
const emotionMap = {
  // 表情
  smile: 'appkefu_f001.png',
  lipping: 'appkefu_f002.png',
  color: 'appkefu_f003.png',
  stunned: 'appkefu_f004.png',
  proud: 'appkefu_f005.png',
  tears: 'appkefu_f006.png',
  shy: 'appkefu_f007.png',
  shutUp: 'appkefu_f008.png',
  sleep: 'appkefu_f009.png',
  crying: 'appkefu_f010.png',
  embarrassment: 'appkefu_f011.png',

  angry: 'appkefu_f012.png',
  mischievous: 'appkefu_f013.png',
  baringTeeth: 'appkefu_f014.png',
  surprised: 'appkefu_f015.png',
  sad: 'appkefu_f016.png',
  cool: 'appkefu_f017.png',
  lostName: 'appkefu_f018.png',
  berserk: 'appkefu_f019.png',
  vomit: 'appkefu_f020.png',
  sneaking: 'appkefu_f021.png',
  happy: 'appkefu_f022.png',

  whiteEye: 'appkefu_f023.png',
  pride: 'appkefu_f024.png',
  hunger: 'appkefu_f025.png',
  sleepy: 'appkefu_f026.png',
  panic: 'appkefu_f027.png',
  sweating: 'appkefu_f028.png',
  laughing: 'appkefu_f029.png',
  leisure: 'appkefu_f030.png',
  struggle: 'appkefu_f031.png',
  curse: 'appkefu_f032.png',
  question: 'appkefu_f033.png',

  shh: 'appkefu_f034.png',
  halo: 'appkefu_f035.png',
  crazy: 'appkefu_f036.png',
  fade: 'appkefu_f037.png',
  skeleton: 'appkefu_f038.png',
  knocking: 'appkefu_f039.png',
  goodbye: 'appkefu_f040.png',
  wipingSweat: 'appkefu_f041.png',
  nosePicking: 'appkefu_f042.png',
  applause: 'appkefu_f043.png',
  embarrassing: 'appkefu_f044.png',

  badLaugh: 'appkefu_f045.png',
  leftHem: 'appkefu_f046.png',
  rightHem: 'appkefu_f047.png',
  yawning: 'appkefu_f048.png',
  disdain: 'appkefu_f049.png',
  grievance: 'appkefu_f050.png',
  almostCrying: 'appkefu_f051.png',
  intimate: 'appkefu_f052.png',
  kiss: 'appkefu_f053.png',
  scared: 'appkefu_f054.png',
  pitiful: 'appkefu_f055.png',

  kitchenKnife: 'appkefu_f056.png',
  watermelon: 'appkefu_f057.png',
  beer: 'appkefu_f058.png',
  basketball: 'appkefu_f059.png',
  pingPong: 'appkefu_f060.png',

  coffee: 'appkefu_f061.png',
  rice: 'appkefu_f062.png',
  cake: 'appkefu_f063.png',
  rose: 'appkefu_f064.png',
  fading: 'appkefu_f065.png',
  lips: 'appkefu_f066.png',

  compassion: 'appkefu_f067.png',
  heartbreak: 'appkefu_f068.png',
  pigHead: 'appkefu_f069.png',
  lightning: 'appkefu_f070.png',
  bomb: 'appkefu_f071.png',
  knife: 'appkefu_f072.png',
  football: 'appkefu_f073.png',
  ladybug: 'appkefu_f074.png',
  stool: 'appkefu_f075.png',
  moon: 'appkefu_f076.png',
  sun: 'appkefu_f077.png',

  gift: 'appkefu_f078.png',
  hug: 'appkefu_f079.png',
  strong: 'appkefu_f080.png',
  weak: 'appkefu_f081.png',
  handshake: 'appkefu_f082.png',
  victory: 'appkefu_f083.png',
  holdingFists: 'appkefu_f084.png',
  allure: 'appkefu_f085.png',
  fist: 'appkefu_f086.png',
  poor: 'appkefu_f087.png',
  loveYou: 'appkefu_f088.png',

  no: 'appkefu_f089.png',
  ok: 'appkefu_f090.png',
  love: 'appkefu_f091.png',
  airKiss: 'appkefu_f092.png',
  jump: 'appkefu_f093.png',
  trembling: 'appkefu_f094.png',
  qihuo: 'appkefu_f095.png',
  circle: 'appkefu_f096.png',
  kowtow: 'appkefu_f097.png',
  lookingBack: 'appkefu_f098.png',
  jumpingRope: 'appkefu_f099.png',
  surrender: 'appkefu_f100.png',
  excited: 'appkefu_f101.png',
  randomDance: 'appkefu_f102.png',
  kissing: 'appkefu_f103.png',
  leftTaiChi: 'appkefu_f104.png',
  rightTaiChi: 'appkefu_f105.png'
};

const emotions: IObject = {
  smile: '微笑',
  lipping: '撇嘴',
  color: '色',
  stunned: '发呆',
  proud: '得意',
  tears: '流泪',
  shy: '害羞',
  shutUp: '闭嘴',
  sleep: '睡',
  crying: '大哭',
  embarrassment: '尴尬',

  angry: '发怒',
  mischievous: '调皮',
  baringTeeth: '呲牙',
  surprised: '惊讶',
  sad: '难过',
  cool: '酷',
  lostName: '囧',
  berserk: '抓狂',
  vomit: '吐',
  sneaking: '偷笑',
  happy: '愉快',

  whiteEye: '白眼',
  pride: '傲慢',
  hunger: '饥饿',
  sleepy: '困',
  panic: '惊恐',
  sweating: '流汗',
  laughing: '憨笑',
  leisure: '悠闲',
  struggle: '奋斗',
  curse: '咒骂',
  question: '疑问',

  shh: '嘘',
  halo: '晕',
  crazy: '疯了',
  fade: '衰',
  skeleton: '骷髅',
  knocking: '敲打',
  goodbye: '再见',
  wipingSweat: '擦汗',
  nosePicking: '抠鼻',
  applause: '鼓掌',
  embarrassing: '糗大了',

  badLaugh: '坏笑',
  leftHem: '左哼哼',
  rightHem: '右哼哼',
  yawning: '哈欠',
  disdain: '鄙视',
  grievance: '委屈',
  almostCrying: '快哭了',
  intimate: '阴险',
  kiss: '亲亲',
  scared: '吓',
  pitiful: '可怜',

  kitchenKnife: '菜刀',
  watermelon: '西瓜',
  beer: '啤酒',
  basketball: '篮球',
  pingPong: '乒乓',
  coffee: '咖啡',
  rice: '饭',
  cake: '蛋糕',
  rose: '玫瑰',
  fading: '凋谢',
  lips: '嘴唇',

  compassion: '爱心',
  heartbreak: '心碎',
  pigHead: '猪头',
  lightning: '闪电',
  bomb: '炸弹',
  knife: '刀',
  football: '足球',
  ladybug: '瓢虫',
  stool: '便便',
  moon: '月亮',
  sun: '太阳',

  gift: '礼物',
  hug: '拥抱',
  strong: '强',
  weak: '弱',
  handshake: '握手',
  victory: '胜利',
  holdingFists: '抱拳',
  allure: '勾引',
  fist: '拳头',
  poor: '差劲',
  loveYou: '爱你',

  no: 'No',
  ok: 'OK',
  love: '爱情',
  airKiss: '飞吻',
  jump: '跳跳',
  trembling: '发抖',
  qihuo: '怄火',
  circle: '转圈',
  kowtow: '磕头',
  lookingBack: '回头',
  jumpingRope: '跳绳',

  surrender: '投降',
  excited: '激动',
  randomDance: '乱舞',
  kissing: '献吻',
  leftTaiChi: '左太极',
  rightTaiChi: '右太极'
};
//文字-> 表情
const chatFaceJson: IObject = {};

for (let faceI = 0; faceI <= expressionJson.length - 1; faceI++) {
  chatFaceJson[expressionJson[faceI].meaning] = expressionJson[faceI].url;
}

function faceReg(content: any) {
  content = content.replace(/\[([^\]]{1,3})\]/gi, function (word: any) {
    if (!chatFaceJson[word.replace(/\s/, '')]) {
      return word;
    }
    return '<img class="chat-expression" src="emoji/' + chatFaceJson[word.replace(/\s/, '')] + '">';
  });
  //将content中的\n 和 \r替换成<br>
  content = content.replace(/\n/g, '<br>');
  content = content.replace(/\r/g, '<br>');
  content = wrapHttpMsg(content);
  return content;
}

//替换文本内容：url地址替换为a标签显示
function wrapHttpMsg(content?: string) {
  if (!content) return content;

  // const httpEx = /((https?|ftp|rtsp|mms):\/\/[^\s[]+)/g;
  const httpEx = /((https|http|ftp|rtsp|mms)?:\/\/)[^\s\[\,\，\"\“\”\'\‘\’]+/g;
  return content.replace(httpEx, (match) => {
    return `<a target='_blank' class='max-length' style='max-width: 200px' href='${match}' title='${match}'>${match}</a>`;
  });
}

export default {
  expressionJson,
  faceReg,
  emotionMap,
  emotions
};
